<?php

namespace app\hejiang;

/**
 * Sentry adapter
 * 
 * @property \Raven_Client $client
 * @property ErrorHandler $handler
 */
class Sentry extends \yii\base\Component
{
    /**
     * Sentry raven client
     *
     * @var \Raven_Client
     */
    protected $_client;

    /**
     * Error handler
     *
     * @var ErrorHandler
     */
    protected $_handler;

    /**
     * Sentry options
     *
     * @var array|string
     */
    public $options;

    public function init()
    {
        YII_DEBUG ?: $this->install();
    }

    public function getClient()
    {
        return $this->_client ?: $this->_client = new \Raven_Client($this->options);
    }

    public function getHandler()
    {
        return $this->_handler;
    }

    protected function install()
    {
        $this->_handler = new ErrorHandler($this->client);
        $this->_handler->registerExceptionHandler();
        $this->_handler->registerErrorHandler();
        $this->_handler->registerShutdownFunction();
    }
}